﻿using System;
using System.Collections.Generic;
using System.Linq;
using HaloReachApi.Responses;

namespace HaloReachApi
{
    public enum FileCategory
    {
        Image,
        GameClip,
        GameMap,
        GameSettings
    }

    public enum EngineFilter
    {
        None,
        Campaign,
        Forge,
        Multiplayer,
        Firefight
    }

    public enum DateFilter
    {
        Day,
        Week,
        Month,
        All
    }

    public enum SortFilter
    {
        MostRelevant,
        MostRecent,
        MostDownloads,
        HighestRated
    }

    public class ReachFileSearchService : BaseReachApiJsonService<FileResponse>
    {
        private const string uri = "http://www.bungie.net/api/reach/reachapijson.svc/file/search/{0}/{1}/{2}/{3}/{4}/{5}/{6}?tags={7}";

        public ReachFileSearchService()
            : base()
        { }

        public ReachFileSearchService(string key)
            : base(key)
        { }

        public void GetFileSearchAsync(FileCategory fileCategory, string mapId = "null", 
                                        EngineFilter engineFilter = EngineFilter.None, DateFilter dateFilter = DateFilter.All,
                                        SortFilter sortFilter = SortFilter.MostRelevant, int pageNum = 0,
                                        IEnumerable<string> tags = null)
        {

            var tagString = string.Empty;
            if ( tags != null )
                tagString = String.Join(",", tags.ToArray());

            StartServiceCall(String.Format(uri, apiKey, fileCategory, mapId, engineFilter, dateFilter, sortFilter, pageNum, tagString));
        }
    }
}
